﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;

namespace ALDIOrganizer
{
    /* This part of the Rota class contains fields (and auxilliary methods)
     * required for data presentation - databinding to Windows controls
     * 
     */
    public partial class Rota : Sheet, INotifyPropertyChanged
    {
        #region databinding fields
        public string bndWhichWeek
        {
            get { return Monday.WeekOfYear().ToString(); }
        }

        public string bndDays
        {
            get { return ToString(); }
        }

        public string bndTemplateName
        {
            get
            {
                return TemplateName ?? String.Empty; 
            }
        }

        public string bndAction
        {
            get
            {
                return ProperAction.GetString();
            }
        }

        string _bndTotalHours;
        public string TotalHoursString
        {
            get
            {
                return _bndTotalHours;
            }
            set
            {
                if (value == _bndTotalHours)
                {
                    return;
                }
                _bndTotalHours = value;
                TriggerPropertyChanged("bndTotalHours");
            }
        }

        [NonSerialized]
        string _bndWhoOnHolidays;
        /// <summary>
        /// 
        /// </summary>
        /// <remarks>
        /// It returns nicely presented data, but this data needs to be calculated first
        /// and it'pShift done in the DataFile class, which retrieves holidays from SQLite CurrentFile
        /// and [...]
        /// </remarks>
        /// <see>
        /// DataFile.ComputeHolidays
        /// </see>
        public string WhoOnHolidays
        {
            get
            {
                return _bndWhoOnHolidays;
            }
            set
            {
                if (value == _bndWhoOnHolidays)
                {
                    return;
                }
                _bndWhoOnHolidays = value;
                TriggerPropertyChanged("bndWhoonHolidays");
            }
        }


        public override string ToString()
        {
            return Monday.ToFormattedDateSpan(Sunday);
        }


        #endregion

        





        #region INotifyPropertyChanged Members        
        public event PropertyChangedEventHandler PropertyChanged;
        #endregion

        /// <summary>
        /// Calls PropertyChanged event, making sure if it isn't null
        /// </summary>
        /// <param Name="pPropertyName">
        /// Name of the property that changed
        /// (it has to be passed as a parameter for the event handler)
        /// </param>
        public void TriggerPropertyChanged(string pPropertyName)
        {
            if (PropertyChanged == null)
            {
                return;
            }
            PropertyChanged(this, new PropertyChangedEventArgs(pPropertyName));
        }

    }
}
